// TypeScript file
class startView extends egret.DisplayObjectContainer {
    public constructor() {
        super();
        this.width = 750;
        this.height = 1334;
        this.init();
    }

    private image: egret.Bitmap;

    private init() {
       this.initButton("矩形遮罩", 20, 1000, this.rectMask);
       this.initButton("对象遮罩", 200, 1000, this.spriteMask);
       
        this.initImage();
    }

    //测试
    private test() {
        console.log("测试")
    }

    public spritmask:egret.Sprite;
    //对象遮罩
    private spriteMask(){
        this.image.mask = null;

        this.spritmask = new egret.Sprite();
        this.spritmask.graphics.beginFill( 0x1122cc );
        this.spritmask.graphics.drawArc(200,200,100,0,Math.PI,true);
        this.spritmask.graphics.endFill();

        this.addChild(this.spritmask);

        // this.image.mask = this.spritmask;
    }

    //矩形遮罩
    private rectMask(){
        this.image.mask = null;
        var rect:egret.Rectangle = new egret.Rectangle(20,20,300,300);  
        this.image.mask = rect;
    }

    //初始化图片
    private initImage() {
        if (this.image) {
            this.removeChild(this.image);
            this.image = null;
        }
        this.image = new egret.Bitmap;
        this.image.texture = RES.getRes("1_jpg");
        this.addChild(this.image);
    }

    //通用按钮
    private initButton(textContent, x, y, callback) {
        var text: egret.TextField = new egret.TextField();
        text.text = textContent;
        text.textColor = 0x000000;
        text.background = true;
        text.backgroundColor = 0x03f425;
        text.x = x;
        text.y = y;
        text.touchEnabled = true;
        text.addEventListener(egret.TouchEvent.TOUCH_TAP, callback, this);
        this.addChild(text);
    }

}